package com.qf.data.api;

import com.qf.common.bean.R;
import com.qf.data.service.CheckCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 千锋健哥
 */
@RestController
@RequestMapping("/data/checkcode")
public class CheckCodeController {

    @Autowired
    private CheckCodeService checkCodeService;

    /**
     * 保存验证码到redis中
     * @param phone
     * @param code
     * @return
     */
    @PostMapping("/saveCodeToRedis")
    public R save(@RequestParam(value = "phone") String phone,
                  @RequestParam(value = "code") String code) {
        R r = checkCodeService.save(phone, code);
        return r;
    }

    /**
     * 根据电话号到redis中获取验证码
     * @param phone
     * @return
     */
    @PostMapping("/getCode")
    public R<String> getCode(@RequestParam(value = "phone") String phone) {
        R<String> r = checkCodeService.getCode(phone);
        return r;
    }

}
